import Vue from 'vue'
import VueRouter from 'vue-router'
// import Login from '../views/Login.vue'

Vue.use(VueRouter)

const routes = [{
  path: '/',
  name: 'index',
  component: () => import('../views/home.vue'),
  children: [{
    path: 'users',
    name: 'users',
    component: () => import('../views/users.vue')
  }, {
    path: 'roles',
    name: 'roles',
    component: () => import('../views/roles.vue')
  }, {
    path: 'goods',
    name: 'goods',
    component: () => import('../views/goods.vue')
  }]
}, {
  path: '/home',
  name: 'home',
  component: () => import('../views/home.vue'),
}, {
  path: '/login',
  name: 'login',
  component: () => import('../views/Login.vue'),
}]

const router = new VueRouter({
  routes
})
router.beforeEach((to, from, next) => {
  if (to.name == 'home') {

    if (!localStorage.getItem('userinfo')) {

      next('/')

    }
  }
  next()

})

export default router